package com.xry.service.impl;

import com.xry.annotation.LogMethod;
import com.xry.bean.Order;
import com.xry.mapper.OrderDao;
import com.xry.service.OrderService;
import com.xry.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderDao orderDao;
    @Override
    @LogMethod(serviceName = "增加订单信息")
    public Order add(Order order) {
        //新增数据
        order.setOrder_no("order_"+System.currentTimeMillis());
        orderDao.add(order);
        //通过主键查询数据库中的数据
        Order result = orderDao.one(order.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "修改订单信息")
    public int del(Integer id) {
        return orderDao.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改订单信息")
    public Order edit(Order order) {
        orderDao.edit(order);
        Order result=orderDao.one(order.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "修改订单信息")
    public List<Order> all(Order order) {
        return orderDao.all( order);
    }

    @Override
    public Order one(Integer id) {
        return orderDao.one(id);
    }

    @Override
    public void page(Page page, Order order){
        int count=orderDao.pageCount(order);
        Object data=orderDao.page(page,order);
        page.setCount(count);
        page.setData(data);
    }

    @Override
    public List<Map<String, Integer>> countByDate() {
        return orderDao.countByDate();
    }

    @Override
    public List<Map<String, Integer>> countAmount() {
        return orderDao.countAmount();
    }
}